package main
import (
	"fmt"
)

func testSlice0(){
	var a []int
	if a == nil{
      fmt.Printf("a is nil\n")
	}else{
		fmt.Printf("a = %v\n",a)
	}
	
}
func testSlice1()  {
	a := [5]int{1,2,3,4,5}
	var b []int
	b = a[1:4]
	fmt.Printf("slice b:%v\n",b)
	fmt.Printf("b[0]=%d\n",b[0])
	fmt.Printf("b[1]=%d\n",b[1])
	fmt.Printf("b[2]=%d\n",b[2])
}
func testSlice2()  {
	c := []int{6,7,8}
	fmt.Printf("slice a:%v type if a:%T\n",c,c)
}
func testSlice3()  {
	a := [5]int{1,2,3,4,5}
	var b []int
	b = a[1:4]
	fmt.Printf("slice b:%v\n",b)
	c := a[1:]
	fmt.Printf("slice c:%v\n",c)
	d := a[:4]
	fmt.Printf("slice d:%v\n",d)
	e := a[:]
	fmt.Printf("slice e:%v\n",e)
}
func testSlice4()  {
	a := [...]int{1,2,3,4,5,7,8,9,11}
	fmt.Printf("array a:%v type of a:%T\n",a,a)
	b := a[2:5]
	fmt.Printf("slice b:%v type of b:%T\n",b,b)
	/* 
	b[0] = b[0] + 10
	b[1] = b[1] + 20
	b[2] = b[2] + 30 
	*/
	for index := range b {
		b[index] = b[index]+10
	}
	fmt.Printf("after modify slice b,array a:%v type of a:%T\n",a,a)
	
}

func testSlice5(){
	numa := [3]int{78,79,80}
	s1 := numa[:]
	s2 := numa[:]
	s1[0] = 100
	fmt.Printf("numa=%v s2=%v\n",numa,s2)
	s2[1] = 200
	fmt.Printf("numa%v s1=%v\n",numa,s1)
}
func testAppend(){
	var a []int = []int {1,3,4}
	var b []int = []int {4,5,6}
	c := append(a,b...)
	fmt.Printf("a=%v\n",c)
}

func sumArray(a []int)int  {
	var sum int = 0
	for _,v:=range a {
		sum = sum + v
	}
	return sum
}
func testSumArray()  {
	var a [10]int = [10]int{1,2,3,4,5,6,7,8,9}
	sum := sumArray(a[2:10])
	fmt.Println("sum: ",sum)
}
func testModifyCopy()  {
	var a []int = []int{1,2,3}
	var b []int = []int{3,4,5}
	copy(a,b)
	// a = append(a,b...)
	fmt.Println("a:",a)
	fmt.Println("b:",b)

	
}
 func main()  {
	//  testAppend()
	// testSumArray();
	testModifyCopy()
 }
